/**
 * 加载模型
 */

class ModelLoader {
    constructor(viewer, sc, objects, smallView, dingArr) {
        this.viewer = viewer;
        this.sc = sc;
        this.objects = objects;
        this.smallView = smallView;
        this.dingArr = dingArr;
    }

    loadModel(url) {
        let sc = this.sc;
        let objects = this.objects;
        let smallView = this.smallView;
        let dingArr = this.dingArr;

        return new Promise((resolve, reject) => {
            this.viewer.loadGltf(url, gltf => {
                $('.load-container').hide();

                let model = gltf.scene || gltf.scenes[0];
                model.updateMatrixWorld(true);
                model.traverse(child => {
                    if (child.isMesh) {
                        child.scale.set(sc, sc, sc);

                        objects.push(child);

                        if (child.name.toLowerCase().indexOf("ding") > -1) {
                            dingArr.push(child);
                        }
                    }
                });

                smallView.scene_s && smallView.scene_s.add(model.clone());

                resolve();
            });
        });

    }
}

export { ModelLoader }
